package com.ticket.sass.admin.dto.output.printer;

import com.google.gson.Gson;
import com.ticket.sass.admin.model.LabModel;
import com.ticket.sass.common.entity.tenant.CommodityCloudPrinterEntity;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;

/**
 * @author ywb
 * @date 2024-04-08 11:25
 */
@Data
@ApiModel
public class CommodityCloudPrinterListOutput {
    private Long id;
    
    @ApiModelProperty(value = "名称")
    private String name;
    
    @ApiModelProperty(value = "类型 1 易联云")
    private Short type;
    
    @ApiModelProperty(value = "数据")
    private Object data;
    
    @ApiModelProperty(value = "是否在线")
    private Boolean online = Boolean.FALSE;
    
    @ApiModelProperty(value = "影厅")
    private List<LabModel> halls;
    
    @ApiModelProperty(value = "影厅")
    private List<Long> hallIds;
    
    private Boolean isDefault;
    
    public List<Long> getHallIds() {
        if (halls.size() == 0){
            return new ArrayList<>();
        }
        
        return halls.stream().map(LabModel::getId).collect(Collectors.toList());
    }
    
    public Object getData() {
        if (Objects.isNull(data)){
            return null;
        }
        return new Gson().fromJson(data.toString(), Object.class);
    }
    
    public CommodityCloudPrinterListOutput() {
    
    }
    
    public CommodityCloudPrinterListOutput(CommodityCloudPrinterEntity entity) {
        this.id = entity.getId();
        this.name = entity.getName();
        this.type = entity.getType() != null ? entity.getType().getValue() : 1;
        this.data = entity.getData();
        // Assuming 'halls' and 'hallIds' are already populated elsewhere
        this.halls = new ArrayList<>(); // Initialize if not already initialized
        this.hallIds = new ArrayList<>(); // Initialize if not already initialized
        this.isDefault = entity.getIsDefault();
    }
}
